package com.spit.hkpost.bean.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.spit.fammo.bean.db.ListingBean

/**
 * @Author nike
 * @Date 2023/9/6 17:42
 * @Description
 */
@Dao
interface ListingDao {

    /**
     * 增加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun add(vararg bean: ListingBean)

    @Query("SELECT * FROM ListingBean WHERE fatherrono = :fatherrono")
    fun findAll(fatherrono: String?): List<ListingBean>

    @Query("SELECT * FROM ListingBean WHERE fatherrono = :fatherrono AND type =:type")
    fun findAll(fatherrono: String?, type: Int): List<ListingBean>

    //删除数据库表全部数据
    @Query("delete from ListingBean")
    suspend fun deleteAll()

    /**
     * 更新
     */
    @Update
     fun update(bean: ListingBean)

    suspend fun insertOrUpdate(bean: ListingBean) {
        if (bean == null){
            add(bean)
        }else{
            update(bean)
        }
    }

}